/*
 * Copyright 2008 Nathan C Jones
 * 
 * This file is part of Fivehundred.
 * 
 * Fivehundred is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Fivehundred is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * Fivehundred. If not, see <http://www.gnu.org/licenses/>. 
 */

package com.googlecode.fivehundred.ui.simple;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import com.googlecode.fivehundred.model.Card;
import com.googlecode.fivehundred.model.CardPile;
import com.googlecode.fivehundred.model.Deck;
import com.googlecode.fivehundred.model.Hand;

/**
 * A visual card game board with a game status area, a discard area, and a
 * player hand area.
 * 
 * @author Nathan C Jones
 */
public class GameBoard extends JPanel {

	private static final long serialVersionUID = 1016370650498079425L;

	public GameBoard() {
		init();
	}

	private static final Hand HAND = new Hand();

	private static final int HAND_SIZE = 10;

	private void init() {
		setOpaque(true);
		setBackground(new Color(0, 128, 0));

		setLayout(new BorderLayout());

		final GameInfoPanel gameInfoBoard = new GameInfoPanel();
		add(gameInfoBoard, BorderLayout.NORTH);

		final DiscardPanel discardPanel = new DiscardPanel(new CardPile());
		discardPanel.setBorder(BorderFactory.createLineBorder(Color.green, 3));
		add(discardPanel, BorderLayout.CENTER);
		discardPanel.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(final MouseEvent e) {
				new Thread(new Runnable() {
					public void run() {
						final CardPile pile = new CardPile();
						for (final Card c : Deck.FIVE_HUNDRED_DECK) {
							pile.add(c);
						}
						pile.shuffle();
						final Card card = pile.removeTop();
						HAND.add(card);
					}
				}).start();
			}
		});

		final JHand playerCardPanel = new JHand(HAND);
		playerCardPanel.setBorder(BorderFactory.createLineBorder(Color.red, 3));
		add(playerCardPanel, BorderLayout.SOUTH);
	}

}
